import util from "../utils/util.js";
//获取token
function getTokenModel() {
  return new Promise(resolve => {
      //获取code
      wx.login({
        success(res) {
          if (res.code) {
            resolve(res);
          } else {
            util.showToast("获取用户信息失败");
          }
        }
      });
    })
    .then(res => {
      //获取授权信息
      if (!res.code) {
        return util.showToast("授权失败！");
      }
      const url = util.api.user;
      const data = {
        code: res.code
      };
      const method = "POST";
      return util.sendRequest(url, method, data);
    })
}


//发送验证码
function sendCodeModel(phone,template) {
  const url = util.api.SendSms;
  const data = {
      token: util.token,
      phone: phone,
      template
  };
  const method = "GET";
  return util.sendRequestFail(url, method, data)
}
export {
  getTokenModel,
  sendCodeModel
};